package com.ihr360.insurance.model.dto.ledger;

import com.ihr360.authority.sharing.entityhandler.UserResourceHandler;
import com.ihr360.commons.model.type.SIHFLedgerState;
import com.ihr360.insurance.model.dto.ledger.embeddable.HouseFundLedgerSummary;
import com.ihr360.insurance.model.dto.ledger.embeddable.SocialInsuranceLedgerSummary;
import com.ihr360.insurance.model.meta.DynamicFooter;
import com.ihr360.insurance.model.meta.DynamicHeader;
import com.ihr360.shared.entitywithlistener.NumberIdWithTimeAndCompanyId;
import com.vladmihalcea.hibernate.type.json.JsonBinaryType;
import com.vladmihalcea.hibernate.type.json.JsonStringType;
import org.hibernate.annotations.Type;
import org.hibernate.annotations.TypeDef;
import org.hibernate.annotations.TypeDefs;

import javax.persistence.Column;
import javax.persistence.Embedded;
import javax.persistence.Entity;
import javax.persistence.EntityListeners;
import javax.persistence.EnumType;
import javax.persistence.Enumerated;
import javax.persistence.Table;
import javax.persistence.UniqueConstraint;

/**
 * 社保公积金月度台账统计汇总信息。
 * <b>每个账号每月只有一份社保公积金台账</b>
 * <ul>
 * <li>账单月份</li>
 * <li>社保缴纳人数</li>
 * <li>公积金缴纳人数</li>
 * <li>社保缴费</li>
 * <li>公积金缴费</li>
 * <li>社保增员人数</li>
 * <li>公积金增员人数</li>
 * <li>社保停缴人数</li>
 * <li>公积金停缴人数</li>
 * </table>
 *
 * @author davidwei
 */
@TypeDefs({
        @TypeDef(name = "json", typeClass = JsonStringType.class),
        @TypeDef(name = "jsonb", typeClass = JsonBinaryType.class)
})
@Entity
@EntityListeners(value = {UserResourceHandler.class})
@Table(uniqueConstraints = @UniqueConstraint(columnNames = {"companyId", "userId", "ledgerYear", "ledgerMonth"}))
public class MonthlyLedgerSummary extends NumberIdWithTimeAndCompanyId<Long> {
    private static final long serialVersionUID = 8520868489683700908L;
    /**
     * 用户id
     */
    @Column(length = 40)
    private String userId;

    /**
     * 台账所属年
     */
    @Column(nullable = false, length = 10)
    private Integer ledgerYear;

    /**
     * 台账所属月
     */
    @Column(nullable = false, length = 4)
    private Integer ledgerMonth;

    /**
     * 社保部分汇总
     */
    @Embedded
    private SocialInsuranceLedgerSummary siLedgerSummary;
    /**
     * 公积金部分汇总
     */
    @Embedded
    private HouseFundLedgerSummary hfLedgerSummary;

    /**
     * blob，二进制形式的长文本数据,BLOB类型 最大65535=64k
     * 这里面放了行内的所有数据，数据通过序列化后存入
     * 表头信息
     */
    @Column(columnDefinition = "text")
    @Type(type = "json")
    private DynamicHeader header;

    /**
     * 表尾信息
     */
    @Column(columnDefinition = "text")
    @Type(type = "json")
    private DynamicFooter footer;
    /**
     * 当前状态
     */
    @Column(length = 20)
    @Enumerated(EnumType.STRING)
    private SIHFLedgerState ledgerState;

    @Column(length = 40)
    private String applicationId;

    public String getApplicationId() {
        return applicationId;
    }

    public void setApplicationId(String applicationId) {
        this.applicationId = applicationId;
    }

    public String getUserId() {
        return userId;
    }

    public void setUserId(String userId) {
        this.userId = userId;
    }

    public Integer getLedgerYear() {
        return ledgerYear;
    }

    public void setLedgerYear(Integer ledgerYear) {
        this.ledgerYear = ledgerYear;
    }

    public Integer getLedgerMonth() {
        return ledgerMonth;
    }

    public void setLedgerMonth(Integer ledgerMonth) {
        this.ledgerMonth = ledgerMonth;
    }

    public SocialInsuranceLedgerSummary getSiLedgerSummary() {
        return siLedgerSummary;
    }

    public void setSiLedgerSummary(SocialInsuranceLedgerSummary siLedgerSummary) {
        this.siLedgerSummary = siLedgerSummary;
    }

    public HouseFundLedgerSummary getHfLedgerSummary() {
        return hfLedgerSummary;
    }

    public void setHfLedgerSummary(HouseFundLedgerSummary hfLedgerSummary) {
        this.hfLedgerSummary = hfLedgerSummary;
    }

    public DynamicFooter getFooter() {
        return footer;
    }

    public void setFooter(DynamicFooter footer) {
        this.footer = footer;
    }

    public SIHFLedgerState getLedgerState() {
        return ledgerState;
    }

    public void setLedgerState(SIHFLedgerState ledgerState) {
        this.ledgerState = ledgerState;
    }

    public DynamicHeader getHeader() {
        return header;
    }

    public void setHeader(DynamicHeader header) {
        this.header = header;
    }
}